//    Copyright (C) Kherty.  All rights reserved.
using System.ComponentModel;
using System.Diagnostics.Contracts;
using System.Reflection;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet
{
    public class PrintOptions: IOfficeXmlSerializable, INotifyPropertyChanged
    {
        #region IOfficeXmlSerializable Members


        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("printOptions"))
            {
                horizontalCentered = c.GetOptionalBoolean("horizontalCentered", false);
                verticalCentered = c.GetOptionalBoolean("verticalCentered", false);
                _headings = c.GetOptionalBoolean("headings", false);
                gridLines = c.GetOptionalBoolean("gridLines", false);
                _gridLinesSet = c.GetOptionalBoolean("gridLinesSet", true);
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("printOptions"))
            {
                c.SetOptionalBoolean("horizontalCentered", horizontalCentered, false);
                c.SetOptionalBoolean("verticalCentered", verticalCentered, false);
                c.SetOptionalBoolean("headings", _headings, false);
                c.SetOptionalBoolean("gridLines", gridLines, false);
                c.SetOptionalBoolean("gridLinesSet", _gridLinesSet, true);
            }
        }

        #endregion


        private bool _gridLinesSet;

        public bool GridLinesSet
        {
            get { return _gridLinesSet; }
            set { _gridLinesSet = value; }
        }
	
        private bool verticalCentered;

        public bool VerticalCentered
        {
            get { return verticalCentered; }
            set { verticalCentered = value; }
        }
	
        private bool horizontalCentered;

        public bool HorizontalCentered
        {
            get { return horizontalCentered; }
            set { horizontalCentered = value; }
        }
	
        private bool gridLines = false;

        public bool GridLinesVisible
        {
            get { return gridLines; }
            set
            {
                if (gridLines == value)
                    return;
                gridLines = value;
                NotifyPropertyChanged("GridLinesVisible");
            }
        }
        private bool _headings = false;

        public bool RowColumnHeadersVisible
        {
            get { return _headings; }
            set
            {
                _headings = value;
                NotifyPropertyChanged("RowColumnHeadersVisible");
            }
        }

        #region INotifyPropertyChanged Members

        public event PropertyChangedEventHandler PropertyChanged;
        void NotifyPropertyChanged(string propertyName)
        {
            Contract.Requires(GetType().GetProperty(propertyName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) != null);
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

    }
}
